#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

int main()
{
    int fd1 = open("work2.txt", O_WRONLY | O_CREAT | O_TRUNC, 0666);
    int txt1[] = {1,2,3,4,5};
    write(fd1, txt1, sizeof(int)*5);//第三个参数是写入的字节数
    close(fd1);

    int fd2 = open("work2.txt", O_RDONLY);
    int txt2[10] = {0};
    lseek(fd2, sizeof(int)*2, SEEK_SET);
    read(fd2, txt2, sizeof(int)*5);
    for (int i=0; i<10; i++)
    {
        printf("txt2[%d]: %d\n", i, txt2[i]);
    }
    close(fd2);


    return 0;
}
